const p1 = new Promise(function (resolve, reject) {
    setTimeout(() => reject(new Error('fail')), 1000)
})

const p2 = new Promise(function (resolve, reject) {
    setTimeout(() => resolve(p1), 2000)
})

p2
    .then(result => console.log(result))
    .catch(error => console.log(error))


new Promise((resolve, reject) => {
    // 在本轮 stack 上任务执行完之后执行
    // 因此依然会在 2 打印出来之后
    resolve(1);
    console.log(2);
}).then(r => {
    console.log(r);
});
